# 请在这里完成你的代码
import numpy as np
import cv2 as cv
cap = cv.VideoCapture('bike.mp4')

while cap.isOpened():

    ret, frame = cap.read()
    if not ret:
        print("没有内容，退出啦 :) ")
        break
    gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    cv.imshow('original',gray)
    fCoef = np.fft.fft2(gray)
    mag_spec = np.abs(fCoef)
    mag_spec_sorted = np.sort(mag_spec.ravel())
    keep_list = [0.5, 0.05]
    for i,keep in enumerate(keep_list):
        thresh = mag_spec_sorted[int((1 - keep) * gray.size)]
        mask = mag_spec > thresh
        fCoef_compressed = fCoef * mask
        img_cp = np.fft.ifft2(fCoef_compressed).real

        cv.imshow(f"{keep}", np.uint8(img_cp))

        if cv.waitKey(1) == ord('q'):
            break

# 释放视频捕捉资源
cap.release()

# 关闭所有的 GUI 窗口
cv.destroyAllWindows()
